]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
lookingGlass: Handle completions asynchronously
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 12 Jul 2023 23:52:06 +0000 (01:52 +0200)
committerMarge Bot <marge-bot@gnome.org>
Fri, 14 Jul 2023 12:36:53 +0000 (12:36 +0000)
They will actually become asynchronous in a following commit,
prepare for that.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2842>

js/ui/lookingGlass.js

index 05006d837778447ea4f75e04f022f388c16d7838..fd19e713e587a9e2471969483cce10232383f418 100644 (file)
@@ -94,30 +94,29 @@ var AutoComplete = class AutoComplete extends Signals.EventEmitter {
         }
     }
 
+    async _handleCompletions(text, time) {
+        const [completions, attrHead] =
+            await JsParse.getCompletions(text, commandHeader, AUTO_COMPLETE_GLOBAL_KEYWORDS);
+
+        const tabType = (time - this._lastTabTime) < AUTO_COMPLETE_DOUBLE_TAB_DELAY
+            ? 'double' : 'single';
+
+        this._processCompletionRequest({
+            tabType,
+            completions,
+            attrHead,
+        });
+        this._lastTabTime = time;
+    }
+
     _entryKeyPressEvent(actor, event) {
         let cursorPos = this._entry.clutter_text.get_cursor_position();
         let text = this._entry.get_text();
         if (cursorPos != -1)
             text = text.slice(0, cursorPos);
 
-        if (event.get_key_symbol() == Clutter.KEY_Tab) {
-            let [completions, attrHead] = JsParse.getCompletions(text, commandHeader, AUTO_COMPLETE_GLOBAL_KEYWORDS);
-            let currTime = global.get_current_time();
-            if ((currTime - this._lastTabTime) < AUTO_COMPLETE_DOUBLE_TAB_DELAY) {
-                this._processCompletionRequest({
-                    tabType: 'double',
-                    completions,
-                    attrHead,
-                });
-            } else {
-                this._processCompletionRequest({
-                    tabType: 'single',
-                    completions,
-                    attrHead,
-                });
-            }
-            this._lastTabTime = currTime;
-        }
+        if (event.get_key_symbol() === Clutter.KEY_Tab)
+            this._handleCompletions(text, event.get_time()).catch(logError);
         return Clutter.EVENT_PROPAGATE;
     }